﻿using AutoMapper;
using BW.EatRabbit.API.Application.Commands.Immune;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Immune
{
    public class ImmuneCreateCommandHandler : IRequestHandler<ImmuneCreateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Immune_Information> _immuneRepository;
        private readonly IMapper _mapper;
        public ImmuneCreateCommandHandler(IBaseRepository<Immune_Information> immuneRepository, IMapper mapper)
        {
            _immuneRepository = immuneRepository;
            _mapper = mapper;

        }
        public Task<APIResult<int>> Handle(ImmuneCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            Immune_Information immune=_mapper.Map<Immune_Information>(request);

            immune.Creator = request.UserNickname;

            _immuneRepository.AddEntity(immune);
            return Task.FromResult(result);

        }
    }
}
